package facade;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Column;
import javax.persistence.EntityManager;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entidad.Pais;

/**
 * Session Bean implementation class PaisFacade
 */
@Stateless
@LocalBean
public class PaisFacade implements PaisFacadeRemote {

	@PersistenceContext(unitName = "sgh001EJB")
	private EntityManager em;
	
	
	
    public PaisFacade() {
        
    }

	@Override
	public List<Pais> Listar() {
		Query query = em.createQuery("select p from Pais p order by p.nombrePais");		
		@SuppressWarnings("unchecked")
		List<Pais> result = query.getResultList();
		return result;
	}

	@Override
	public void Save(Pais objPais) {
		try {			
			em.persist(objPais);			
		} catch (Exception e) {			
		}
	}

	@Override
	public void Update(Pais objPais) {
		try {			
			em.merge(objPais);			
		} catch (Exception e) {			
		}
	}

	@Override
	public void Delete(String id) {
		Pais objPais = new Pais();
		try {
			objPais = em.find(Pais.class, id);
			if(objPais != null){				
				em.remove(objPais);				
			}			
		} catch (Exception e) {
			
		}	
	}

	@Override
	public Pais Find(String id) {
		try {		
			return em.find(Pais.class, id);			
		} catch (Exception e) {
			return null;
		}
	}

}
